home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Audio / AC3 / AC3Dec / exponent.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-06  |  3.1 KB  |  136 lines

  1. /* 
  2.  *    exponent.c
  3.  *
  4.  *    Copyright (C) Aaron Holtzman - May 1999
  5.  *
  6.  *  This file is part of ac3dec, a free Dolby AC-3 stream decoder.
  7.  *    
  8.  *  ac3dec is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  ac3dec is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  */
  23.  
  24.  
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include "ac3.h"
  28. #include "ac3_internal.h"
  29.  
  30.  
  31. #include "decode.h"
  32. #include "exponent.h"
  33.  
  34.  
  35. static void exp_unpack_ch(uint_16 type,uint_16 expstr,uint_16 ngrps,uint_16 initial_exp, 
  36.         uint_16 exps[], uint_16 *dest);
  37.  
  38. void
  39. exponent_unpack( bsi_t *bsi, audblk_t *audblk)
  40. {
  41.     uint_16 i;
  42.  
  43.     for(i=0; i< bsi->nfchans; i++)
  44.         exp_unpack_ch(UNPACK_FBW, audblk->chexpstr[i], audblk->nchgrps[i], audblk->exps[i][0], 
  45.                 &audblk->exps[i][1], audblk->fbw_exp[i]);
  46.  
  47.     if(audblk->cplinu)
  48.         exp_unpack_ch(UNPACK_CPL, audblk->cplexpstr, audblk->ncplgrps, audblk->cplabsexp << 1,    
  49.                 audblk->cplexps, &audblk->cpl_exp[audblk->cplstrtmant]);
  50.  
  51.     if(bsi->lfeon)
  52.         exp_unpack_ch(UNPACK_LFE, audblk->lfeexpstr, 2, audblk->lfeexps[0], 
  53.                 &audblk->lfeexps[1], audblk->lfe_exp);
  54. }
  55.  
  56.  
  57. static void
  58. exp_unpack_ch(uint_16 type,uint_16 expstr,uint_16 ngrps,uint_16 initial_exp, 
  59.         uint_16 exps[], uint_16 *dest)
  60. {
  61.     uint_16 i,j;
  62.     sint_16 exp_acc;
  63.     sint_16 exp_1,exp_2,exp_3;
  64.  
  65.     if(expstr == EXP_REUSE)
  66.         return;
  67.  
  68.     /* Handle the initial absolute exponent */
  69.     exp_acc = initial_exp;
  70.     j = 0;
  71.  
  72.     /* In the case of a fbw channel then the initial absolute values is 
  73.      * also an exponent */
  74.     if(type != UNPACK_CPL)
  75.         dest[j++] = exp_acc;
  76.  
  77.     /* Loop through the groups and fill the dest array appropriately */
  78.     for(i=0; i< ngrps; i++)
  79.     {
  80.         if(exps[i] > 124)
  81.             goto error;
  82.  
  83.         exp_1 = exps[i] / 25;
  84.         exp_2 = (exps[i] - (exp_1 * 25)) / 5;
  85.         exp_3 = exps[i] - (exp_1 * 25) - (exp_2 * 5) ;
  86.  
  87.         exp_acc += (exp_1 - 2);
  88.  
  89.         switch(expstr)
  90.         {
  91.             case EXP_D45:
  92.                 dest[j++] = exp_acc;
  93.                 dest[j++] = exp_acc;
  94.             case EXP_D25:
  95.                 dest[j++] = exp_acc;
  96.             case EXP_D15:
  97.                 dest[j++] = exp_acc;
  98.         }
  99.  
  100.         exp_acc += (exp_2 - 2);
  101.  
  102.         switch(expstr)
  103.         {
  104.             case EXP_D45:
  105.                 dest[j++] = exp_acc;
  106.                 dest[j++] = exp_acc;
  107.             case EXP_D25:
  108.                 dest[j++] = exp_acc;
  109.             case EXP_D15:
  110.                 dest[j++] = exp_acc;
  111.         }
  112.  
  113.         exp_acc += (exp_3 - 2);
  114.  
  115.         switch(expstr)
  116.         {
  117.             case EXP_D45:
  118.                 dest[j++] = exp_acc;
  119.                 dest[j++] = exp_acc;
  120.             case EXP_D25:
  121.                 dest[j++] = exp_acc;
  122.             case EXP_D15:
  123.                 dest[j++] = exp_acc;
  124.         }
  125.     }    
  126.  
  127.     return;
  128.  
  129.             goto error;
  130. error:
  131.     if(!error_flag)
  132.         fprintf(stderr,"** Invalid exponent - skipping frame **\n");
  133.     error_flag = 1;
  134. }
  135.  
  136.